﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using Loki;
using Loki.UI.Win;

namespace Luna.UI.Win
{
    public static class EditorHelper
    {
        private static RepositoryItemLookUpEdit DisplayNameEditor(LokiCollection<DisplayNamedEntity> P_Source, string P_EmptyText)
        {
            string L_EditorName = typeof(DisplayNamedEntity).Name;
            RepositoryItemLookUpEdit L_Return = Loki.UI.Win.GridExtensions.CreateLookupEditor<DisplayNamedEntity>(L_EditorName, x => x.Name, x => x.Name, x => x.ID, P_EmptyText);
            L_Return.DataSource = P_Source;
            return L_Return;
        }

        public static RepositoryItemLookUpEdit AccountCategory(LokiCollection<DisplayNamedEntity> P_Source)
        {
            return DisplayNameEditor(P_Source, Messages.UIValues.NULL_ACCOUNT_CATEGORY);
        }

        public static RepositoryItemLookUpEdit Projects(LokiCollection<DisplayNamedEntity> P_Source, bool P_UseNoInputText = false)
        {
            if (P_UseNoInputText)
            {
                return DisplayNameEditor(P_Source, Messages.UIValues.NOINPUT_PROJECT);
            }
            else
            {
                return DisplayNameEditor(P_Source, Messages.UIValues.NULL_PROJECT);
            }
        }

        public static RepositoryItemLookUpEdit Accounts(LokiCollection<DisplayNamedEntity> P_Source)
        {
            return DisplayNameEditor(P_Source, Messages.UIValues.NULL_ACCOUNT);
        }

        public static void ConfigureAccounts(this LookUpEdit P_Editor, LokiCollection<DisplayNamedEntity> P_Source)
        {
            P_Editor.Configure<DisplayNamedEntity>(x => x.Name, x => x.Name, x => x.ID, P_Source, Messages.UIValues.NULL_ACCOUNT);
        }
    }
}
